function clickHandler(formId){
    var targetId,srcElement,targetElement;
    srcElement=window.event.srcElement;
	if(srcElement.name=="treeChk"){
		if(srcElement.checked==true){		

			autoSelectParents(srcElement);	 

			autoSelectChilds(srcElement);
		}
		else if(srcElement.checked==false){
	
			autoUnselectChilds(srcElement);
		}
	}

    try{
		if(srcElement.className=="imgcla"){
			srcElementId=srcElement.id;
			srcElementIdStr=srcElementId.substring(3,srcElementId.length);
  			expand(srcElement,srcElementIdStr);
  			//document.getElementById("selectedTreeValue").value="";   do not need the document.submit() event for we need no page refresh
  			//document.getElementById("hiddenTargetFrame").value="";
  			//document.getElementById(formId).target="_self";
  			//document.getElementById(formId).submit();
		}
		else if(srcElement.tagName=="A")
		{
		    srcElementId=srcElement.id;
			expand(srcElement,srcElementId);
			document.getElementById("selectedTreeValue").value=srcElement.id;
			document.getElementById("hiddenTargetFrame").value="rightFrame";
			document.getElementById(formId).target="rightTreeFrame";
			document.getElementById(formId).submit();
		}
    }
	catch(Exception)
	{} 
}

function expand(srcElement,srcElementIdStr){
         targetId="div"+srcElementIdStr;   
         targetElement=document.getElementById(targetId);  
         if(targetElement == null) {
         	return;
         }      
         var disp;
         if(targetElement.style.display=="none"){
             targetElement.style.display="";
             srcElement.src="./images/tree/tree-open1.gif";             
             disp=true;
         }else{            
             targetElement.style.display="none";
             srcElement.src="./images/tree/tree-close1.gif"; 
             disp=false;
         }    
   			document.getElementById("exp"+srcElementIdStr).value=disp;   			
			
}
   


function autoSelectParents(srcElement){
	var divid;
	var chkvalue;
	if(srcElement.parentNode.tagName=="DIV"){	

		srcElementParentNodeId=srcElement.parentNode.id;

		chkvalue=srcElementParentNodeId.substring(3,srcElementParentNodeId.length);			
		divid="div"+chkvalue;		
		var i=0;
		var elements;
		var elem;
		
		elements=document.getElementsByTagName("input");
		try{
			for(i=0;i<elements.length-1;i++){
			 elem=elements[i];		
			 if(elem.name=="treeChk"){	
				if(elem.value==chkvalue){
					elem.checked="true";
				}		
			 }	
			}
	  	}catch(Exception){}

	 	autoSelectParents(srcElement.parentNode);
	}
}

function autoSelectChilds(srcElement){
	var i=0;
	var j=0;
	var elements;
	var elem;
	var tardivid;
	var childs;	
	srcElementValue=srcElement.value;	
    tardivid=srcElementValue;   
	elements=document.getElementsByTagName("div");
	try{
		for(i=0;i<elements.length;i++){
			elem=elements[i];		
			elemId=elem.id;
			elemIdValue=elemId.substring(3,elemId.length);
			if(elemIdValue==tardivid)			
			{
				childs=elem.childNodes;						
				for(j=1;j<childs.length;j++){
					if(childs[j].tagName=="INPUT"){
					  if(childs[j].name=="treeChk"){
						childs[j].checked=true;
						autoSelectChilds(childs[j]);
					  }
					}
				}
			}		
		}
  	}catch(Exception){}
}

function autoUnselectChilds(srcElement){
	var i=0;
	var j=0;
	var elements;
	var elem;
	var tardivid;
	var childs;
    tardivid=srcElement.value;    

	elements=document.getElementsByTagName("div");
	try{
		for(i=0;i<elements.length;i++){
			elem=elements[i];				
			elemId=elem.id;
			elemIdValue=elemId.substring(3,elemId.length);
			if(elemIdValue==tardivid){
				childs=elem.childNodes;		
				for(j=1;j<childs.length;j++){
					if(childs[j].tagName=="INPUT"){
					  if(childs[j].name=="treeChk"){
						childs[j].checked=false;
						autoUnselectChilds(childs[j]);
					  }
					}
				}
			}		
		}
	}catch(Exception){}		
}

 